﻿using ArtMath.Core.Data;
using ArtMath.Core.Helper;
using System;

namespace ArtMath.PointCollection
{
    [Serializable]
    public class Ellipse : ConicBase
    {
        public double LongAxisHalfLength, ShortAxisHalfLength;
        public Ellipse()
        {

        }
        public Ellipse(PointD center, double rotate, double a, double b) : base(center, rotate)
        {
            LongAxisHalfLength = a;
            ShortAxisHalfLength = b;
        }
        public bool IsZero
        {
            get { return LongAxisHalfLength == 0 || ShortAxisHalfLength == 0; }
        }
        public override bool Contains(PointD pt)
        {
            double c = Math.Sqrt(LongAxisHalfLength * LongAxisHalfLength - ShortAxisHalfLength * ShortAxisHalfLength);
            PointD f1 = Center.Offset(RotateAngle, c), f2 = Center.Offset(RotateAngle + Math.PI, c);
            return (pt.DistanceTo(f1) + pt.DistanceTo(f2)).AlmostEqual(2 * LongAxisHalfLength) && AfterContains(pt);
        }
    }
}
